import * as dotenv from "dotenv";
import { DataSource } from "../package/index";
import path from "path";
if (process.env.NODE_ENV !== "production") {
  dotenv.config({ debug: true });
}

const entitiesFile = path.join(__dirname, "./entity/**/*.js");
const migrationsFile = path.join(__dirname, "./migration/**/*.js");

const AppDataSource = new DataSource({
  username: process.env.DB_USER,
  password: process.env.DB_PWD,
  database: process.env.DB_DATABASE,
  host: process.env.DB_HOST || "localhost",
  port: Number(process.env.DB_PORT) || 3000,
  entities: [entitiesFile],
  migrations: [migrationsFile], // 迁移文件路径
  migrationsRun: true,
  synchronize: false,
  type: "gaussdb",
  logging: ["query", "error"],
});

export default AppDataSource;
